package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.AlipayConfigBean;
import com.koron.css2.baseConfig.mapper.AlipayConfigMapper;
import com.koron.css2.baseConfig.queryBean.AlipayConfigQueryBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 支付宝配置-查询
 *
 * @author 廖祥仁
 */
public class AlipayConfigQuery implements ServerInterface {

    private static Logger logger = LogManager.getLogger(AlipayConfigQuery.class);

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {

        MessageBean<AlipayConfigBean> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", AlipayConfigBean.class);
        try {
            AlipayConfigQueryBean bean = JsonUtils.objectToPojo(req.getData(), AlipayConfigQueryBean.class);
            AlipayConfigMapper mapper = factory.getMapper(AlipayConfigMapper.class);
            if (StringUtils.isEmpty(bean.getId())) {
                return MessageBean.create(Constant.ILLEGAL_PARAMETER, "id为空", void.class);
            }
            AlipayConfigBean query = mapper.selectAlipayConfigById(bean.getId());
            info.setData(query);
        } catch (Exception e) {
            info.setCode(Constant.MESSAGE_INT_FAIL);
            info.setDescription(e.getMessage());
            logger.error(e.getMessage(), e);
        }
        return info;
    }
}
